<?php
/**
 * Email Service
 * @author allen
 */

require_once '../app/core/services/BaseService.php';
require_once '../app/models/EmailLogDao.php';
require_once '../app/models/SpecialProductItemDao.php';
require_once '../app/models/UserDao.php';


class EmailService extends BaseService {
	
	private $emailLogDao;
	private $campusDao;
	private $specialProductItemDao;
	private $userDao;

	/**
	 * 1.订单提交通知邮件
	 * 2.订单确认通知邮件
	 * 3.已发货通知邮件
	 * 4.校园大使已收货通知邮件
	 * 5.订单交易成功通知邮件
	 * 6.用户注册通知邮件
	 * 7.用户找回密码通知邮件
	 * 8.后台管理群发通知邮件
	 */
	
    public function __construct(){
         parent::__construct();
         $this->emailLogDao = new EmailLogDao($this->dbUtil);
         $this->campusDao = new CampusDao($this->dbUtil);
         $this->specialProductItemDao = new SpecialProductItemDao($this->dbUtil);
         $this->userDao = new UserDao($this->dbUtil);
    }
	
	//用户注册成功后发邮件让用户激活状态
    public function activeEmailView($param = array()){    
        $username = $param['name'];
        $link = $param['link'];
        $email = $param['email'];
        $recommendGoods = $this->specialProductItemDao->getProductItemsByType(2);
        //生成推荐产品html
        $recommendGoodsHtml = "";
        if(!empty($recommendGoods)){
	        foreach ($recommendGoods as $key => $item) {
	        	if($key < 6){
		        	$urlTitle = $item["url_title"];
		        	$imagePath = ConfigConstants::getProductImagePath($item["ifolder"], $item["iname"], 250);
		        	$recommendGoodsHtml .= "<td height='120'>
		        	                          <a href='http://www.akimimi.com/p/{$urlTitle}'>
								        	    <img src='http:{$imagePath}' width='98' height='98'  style='border:solid 1px #ccc;' alt=''/>
								        	  </a>
								            </td>";
	        	}
	        }
        }
        
        
        $activeRegisterHtml =
<<<str_result

<table width="651" border="0" cellpadding="0" cellspacing="0" style="font-size:12px;">
    <tr>
        <td width="183" rowspan="2"><img src="http://i.akimimi.com/t/default_zh_cn/image/email/email_05.gif" width="172" height="67"  alt=""/></td>
    </tr>
    <tr>
        <td width="468" background="http://i.akimimi.com/t/default_zh_cn/image/email/email_02.jpg"  style=" padding-left:20px; line-height:18px;">
		每一天，我们都在为让您更满意而努力~点滴改变，创造完美购物体验！<br />
		阿基米米，全心为您！让您以最低价买到正品行货。
        </td>
    </tr>
</table>


<table style="float:left; width:210px; margin-top:20px;font-size:12px;" >
    <tr>
      <td><img src="http://i.akimimi.com/t/default_zh_cn/image/email/email_08.gif" width="165" height="241" alt="" /></td>
    </tr>
</table>

<table width="430"  border="0" cellpadding="0" cellspacing="0"  style=" font-size:12px;border:solid 1px #CCC; padding:10px; margin:10px; float:left;">
    <tr>
      <td colspan="2" style="">您好,{$username}！恭喜您成为阿基米米网上商城的会员。</td>
    </tr>
    <tr>
      <td colspan="2" style=""> 我们将为您提供安全、便利、快捷、周到的网络购物服务，</td>
    </tr>
    <tr>
        <td colspan="2" style="" >努力让您以最低价买到正品行货。祝您在阿基米米网上商城购物愉快！</td>
    </tr>
    <tr>
      <td colspan="2">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="2" style="color:#afafaf; font-weight:bold; ">请在24小时内点击下面的链接，完成邮箱验证，您将立刻获得10个积分。</td>
    </tr>
    <tr>
      <td colspan="2" style="line-height:20px; font-family:Arial, Helvetica, sans-serif;" >
        $link
      </td>
    </tr>
    <tr>
        <td colspan="2" style="line-height:20px; color:#9c9c9c;" >如果您不能点击此链接，请将以上链接复制到浏览器地址栏中访问</td>
    </tr>
    <tr>
        <td width="245" height="120" align="right">阿基米米网上商城</td>
        <td width="202" height="120"><img src="http://i.akimimi.com/t/default_zh_cn/image/email/email_11.gif" width="202" height="96" alt="" /></td>
    </tr>
</table>

<span style="clear:both"></span>

<table width="650" border="0" cellpadding="0" cellspacing="0" style="font-size:12px;">
    <tr>
        <td colspan="6" bgcolor="#f6f6f6"><img src="http://i.akimimi.com/t/default_zh_cn/image/email/email_16.gif" width="260" height="26" alt="" /></td>
    </tr>
    <tr>
        {$recommendGoodsHtml}
    </tr>
    <tr>
        <td colspan="6" bgcolor="#f6f6f6"><img src="http://i.akimimi.com/t/default_zh_cn/image/email/email_38.gif" width="325" height="26" alt="" /></td>
    </tr>
    <tr>
        <td height="85" colspan="6">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;米米校园团队是一支<span style="color:#79b440;">极具热情</span>和<span style="color:#79b440;">执行力</span>的大学生创业团队，一支保持旺盛的<span style="color:#79b440;">思想力</span>和<span style="color:#79b440;">创造力</span>的年轻团队，也是一支融会了<span style="color:#79b440;">校园文化底蕴</span>和<span style="color:#79b440;">商业价值内涵</span>的精英团队。米米校园团队由了解电子商务，热爱阿基米米，拥有创业激情和理想的在校大学生自行组建。阿基米米旨在与大学生<span style="color:#79b440;">一起创业</span>。</td>
    </tr>
    <tr>
        <td colspan="6" align="center" bgcolor="#F6F6F6" style="color:#30F; line-height:30px;">此信由阿基米米网上商城系统发出，请勿回复。</td>
    </tr>
</table>

str_result;

        //保存email日志
        $email_type = 6;
        $send_to = "$username<$email>";
        $send_cc = "";
        $description = "用户注册通知邮件";
        $arr_param = array(
            'email_type' => $email_type,
            'send_to' => $send_to,
            'send_cc' => $send_cc,
            'description' => $description,
            'created' => date('Y-m-d H:i:s'),
            'modified' => date('Y-m-d H:i:s')
        );
        self::saveLogs($arr_param);
        
        return $activeRegisterHtml;
    }
    
    /**
     * 订单提交邮件
     */
    public function orderSubmitEmail($param = array()){
    	$orderInfo = $param["orderInfo"];
    	$orderItemInfo = $param["orderItemInfo"];
    	$userName = $param["username"];
    	$email = $param["email"];
    	$orderNumber = $orderInfo[0]["order_num"];
    	$orderTotal = $orderInfo[0]["total"];
        $orderHtml =
<<<str_result
<table style="font-family:'宋体'; font-size:12px; color:#666666;">
        <!-- header begin -->
    
        <tr>
            <td background="http://i.akimimi.com/t/default_zh_cn/image/email/email_002.jpg" style="width:650px;height:95px;" colspan="2">
                <br/><br/><br/><br/><br/>
                    <span>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    </span>
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com">首页</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/mobile_and_accessories">手机</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/dc_and_accessories">数码相机</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/women_costume">时尚女装</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/makeup">化妆品</a></span>
            </td>       
        </tr>
        <!-- header end -->
        
        <!-- center end -->
        <tr>
            <td>
                <table>
                    <tr style="color:#000000">
                        <td>
                            <span style="font-weight:bold;">亲爱的：{$userName}</span><br/><br/>
                                                                            欢迎您来阿基米米购物！您的订单{$orderNumber}已经成功提交。<br/><br/>
                                                                            订单信息<br/><br/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <table  width="440" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#F7FFF4">
                                <tr>
                                    <td width="250" height="25" align="center">商品名称</td>
                                    <td width="89" align="center">数量</td>
                                    <td width="73" align="center">单价</td>
                                </tr>
str_result;
        //显示订单详情
        $unit = UNIT; 
        foreach ($orderItemInfo as $item) {
        	$orderHtml .="
                                <tr>
                                    <td height='25' align='center'><a href='http://www.akimimi.com/p/{$item["url_title"]}'>{$item["title"]}</a></td>
                                    <td align='center'>{$item["quantity"]}</td>
                                    <td align='center'>{$unit}{$item["deal_price"]}</td>
                                </tr>
                          ";
        }
        
        $orderHtml .="                                
                                <tr>
                                    <td height='25' align='center'>&nbsp;</td>
                                    <td colspan='2' align='center'><h3 style='color:#47A618'>合计：{$unit}{$orderTotal}</h3></td>
                                </tr>
                                ";
        
         $orderHtml .=
<<<str_result
                            </table>
                        </td>
                    </tr>
                    <tr style="color:#000000;line-height:22px;">
                        <td>
                            <span style="font-weight:bold; color:#FF0000;">温馨提示：</span>
                            米米客服将在12小时内与您确认订单是否有效，请保持联络畅通。在此期<br/>
                            间，您可以随时进入<span style="color:red;">“订单详情”</span>页面查看订单状态，并进行修改或取消订单的操<br/>
                            作。订单确认后，订单状态将更改为“订单已确认，待发货”。此后，您将不可以自<br/>
                            行修改或取消订单。<br/>                     
                            点击了解<a href="http://www.akimimi.com/">详细售后服务规则</a>。如有任何疑问，欢迎致电：400-66-19686，或联系在线客<br/>服。
                            <br/>
                        </td>
                    </tr>
                </table>
            </td>
            <td style="width:175px;" valign="top">
                <img src="http://i.akimimi.com/t/default_zh_cn/image/email/email_003.jpg"  alt=""/>
            </td>
        </tr>
        <!-- center end -->
        
        <!-- center begin -->
        <tr>
            <td colspan="2" valign="top">
                <img src="http://i.akimimi.com/t/default_zh_cn/image/email/email_001.jpg" alt="" />
            </td>
        </tr>
        <!-- center end -->
    
</table>  
      
str_result;
        //保存email日志
        $email_type = 1;
        $send_to = "$userName<$email>";
        $send_cc = "";
        $description = "订单<{$orderNumber}>提交通知邮件";
        $arr_param = array(
            'email_type' => $email_type,
            'send_to' => $send_to,
            'send_cc' => $send_cc,
            'description' => $description,
            'created' => date('Y-m-d H:i:s'),
            'modified' => date('Y-m-d H:i:s')
        );
        self::saveLogs($arr_param);
        
        return $orderHtml;
    }
    
    /**
     * 订单确认发邮件给下单用户
     */
    public function orderConfirmationEmailToUser($param = array()){
    	$orderInfo = $param["orderInfo"];
    	$orderItemInfo = $param["orderItemInfo"];
    	$userName = $param["username"];
    	$userEmail = $param["userEmail"];
    	$agentUserCampusId = $param["agentUserCampusId"];
    	$agentTeamName = $param["agentTeamName"];
    	$orderNumber = $orderInfo[0]["order_num"];
    	$orderTotal = $orderInfo[0]["total"];
    	$campusInfo = $this->campusDao->getCampusById($agentUserCampusId);
    	$campusName = $campusInfo[0]["area_name"];
        $orderHtml =
<<<str_result
<table style="font-family:'宋体'; font-size:12px; color:#666666;">
        <!-- header begin -->
        <tr>
            <td background="http://i.akimimi.com/t/default_zh_cn/image/email/email_002.jpg" style="width:650px;height:95px;" colspan="2">
                <br/><br/><br/><br/><br/>
                    <span>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    </span>
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com">首页</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/mobile_and_accessories">手机</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/dc_and_accessories">数码相机</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/women_costume">时尚女装</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/makeup">化妆品</a></span>
            </td>       
        </tr>
        <!-- header end -->
        
        <!-- center end -->
        <tr>
            <td>
                <table>
                    <tr style="color:#000000">
                        <td>
                            <span style="font-weight:bold;">亲爱的：{$userName}</span><br/><br/>
                                                                            您的订单{$orderNumber}已经由{$campusName}米米代理{$agentTeamName}确认！<br/><br/>
                                                                            订单信息<br/><br/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <table  width="440" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#F7FFF4">
                                <tr>
                                    <td width="250" height="25" align="center">商品名称</td>
                                    <td width="89" align="center">数量</td>
                                    <td width="73" align="center">单价</td>
                                </tr>
str_result;
        //显示订单详情
        $unit = UNIT; 
        foreach ($orderItemInfo as $item) {
        	$orderHtml .="
                                <tr>
                                    <td height='25' align='center'><a href='http://www.akimimi.com/p/{$item["url_title"]}'>{$item["title"]}</a></td>
                                    <td align='center'>{$item["quantity"]}</td>
                                    <td align='center'>{$unit}{$item["deal_price"]}</td>
                                </tr>
                          ";
        }
        
        $orderHtml .="                                
                                <tr>
                                    <td height='25' align='center'>&nbsp;</td>
                                    <td colspan='2' align='center'><h3 style='color:#47A618'>合计：{$unit}{$orderTotal}</h3></td>
                                </tr>
                                ";
        
         $orderHtml .=
<<<str_result
                            </table>
                        </td>
                    </tr>
                    <tr style="color:#000000;line-height:22px;">
                        <td>
                            <span style="font-weight:bold; color:#FF0000;">温馨提示：</span>
                            您的订单已经确认，我们将在24小时内为您安排发货。阿基米米商城所<br/>
                            有商品均由合作品牌供应商提供，100%原厂正品。在此订单状态下，您不可以自行修<br/>
                            改或删除订单。如您希望修改或删除订单，请致电400-66-19686，由米米客服为您<br/>
                            效劳。<br/>                     
                            欢迎您再次到阿基米米购物，祝您购物愉快！
                            <br/>
                        </td>
                    </tr>
                </table>
            </td>
            <td style="width:175px;" valign="top">
                <img src="http://i.akimimi.com/t/default_zh_cn/image/email/email_007.jpg"  alt=""/>
            </td>
        </tr>
        <!-- center end -->
        
        <!-- center begin -->
        <tr>
            <td colspan="2" valign="top">
                <img src="http://i.akimimi.com/t/default_zh_cn/image/email/email_001.jpg" alt="" />
            </td>
        </tr>
        <!-- center end -->
    
</table>  
      
str_result;
        //保存email日志
        $email_type = 2;
        $send_to = "$userName<{$userEmail}>";
        $send_cc = "";
        $description = "订单<{$orderNumber}>确认通知邮件";
        $arr_param = array(
            'email_type' => $email_type,
            'send_to' => $send_to,
            'send_cc' => $send_cc,
            'description' => $description,
            'created' => date('Y-m-d H:i:s'),
            'modified' => date('Y-m-d H:i:s')
        );
        self::saveLogs($arr_param);
        
        return $orderHtml;
    }
    
    /**
     * 订单确认发邮件给大使
     */
    public function orderConfirmationEmailToAmbassador($param = array()){
    	$orderInfo = $param["orderInfo"];
    	$orderItemInfo = $param["orderItemInfo"];
    	$agentUserEmail = $param["agentUserEmail"];
    	$agentUserName = $param["agentUserName"];
    	$orderNumber = $orderInfo[0]["order_num"];
    	$orderTotal = $orderInfo[0]["total"];
        $orderHtml =
<<<str_result
<table style="font-family:'宋体'; font-size:12px; color:#666666;">
        <!-- header begin -->
    
        <tr>
            <td background="http://i.akimimi.com/t/default_zh_cn/image/email/email_002.jpg" style="width:650px;height:95px;" colspan="2">
                <br/><br/><br/><br/><br/>
                    <span>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    </span>
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com">首页</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/mobile_and_accessories">手机</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/dc_and_accessories">数码相机</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/women_costume">时尚女装</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/makeup">化妆品</a></span>
            </td>       
        </tr>
        <!-- header end -->
        
        <!-- center end -->
        <tr>
            <td>
                <table>
                    <tr style="color:#000000">
                        <td>
                            <span style="font-weight:bold;">亲爱的：{$agentUserName}</span><br/><br/>
                                                                            您已确认订单{$orderNumber}<br/><br/>
                                                                            订单信息<br/><br/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <table  width="440" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#F7FFF4">
                                <tr>
                                    <td width="250" height="25" align="center">商品名称</td>
                                    <td width="89" align="center">数量</td>
                                    <td width="73" align="center">单价</td>
                                </tr>
str_result;
        //显示订单详情
        $unit = UNIT; 
        foreach ($orderItemInfo as $item) {
        	$orderHtml .="
                                <tr>
                                    <td height='25' align='center'><a href='http://www.akimimi.com/p/{$item["url_title"]}'>{$item["title"]}</a></td>
                                    <td align='center'>{$item["quantity"]}</td>
                                    <td align='center'>{$unit}{$item["deal_price"]}</td>
                                </tr>
                          ";
        }
        
        $orderHtml .="                                
                                <tr>
                                    <td height='25' align='center'>&nbsp;</td>
                                    <td colspan='2' align='center'><h3 style='color:#47A618'>合计：{$unit}{$orderTotal}</h3></td>
                                </tr>
                                ";
        
         $orderHtml .=
<<<str_result
                            </table>
                        </td>
                    </tr>
                    <tr style="color:#000000;line-height:22px;">
                        <td>
                            <span style="font-weight:bold; color:#FF0000;">温馨提示：</span>
                            您的订单已经确认，我们将在24小时内为您安排发货。阿基米米商城所<br/>
                            有商品均由合作品牌供应商提供，100%原厂正品。在此订单状态下，您不可以自行修<br/>
                            改或删除订单。如您希望修改或删除订单，请致电400-66-19686，由米米客服为您<br/>
                            效劳。<br/>                     
                            欢迎您再次到阿基米米购物，祝您购物愉快！
                            <br/>
                        </td>
                    </tr>
                </table>
            </td>
            <td style="width:175px;" valign="top">
                <img src="http://i.akimimi.com/t/default_zh_cn/image/email/email_007.jpg"  alt=""/>
            </td>
        </tr>
        <!-- center end -->
        
        <!-- center begin -->
        <tr>
            <td colspan="2" valign="top">
                <img src="http://i.akimimi.com/t/default_zh_cn/image/email/email_001.jpg" alt="" />
            </td>
        </tr>
        <!-- center end -->
    
</table>  
      
str_result;
        //保存email日志
        $email_type = 2;
        $send_to = "$agentUserName<{$agentUserEmail}>";
        $send_cc = "";
        $description = "订单<{$orderNumber}>确认通知邮件";
        $arr_param = array(
            'email_type' => $email_type,
            'send_to' => $send_to,
            'send_cc' => $send_cc,
            'description' => $description,
            'created' => date('Y-m-d H:i:s'),
            'modified' => date('Y-m-d H:i:s')
        );
        self::saveLogs($arr_param);
        
        return $orderHtml;
    }
    
    /**
     * 校园大使已收货确认发邮件给普通用户
     */
    public function orderReceiptEmailToUser($param = array()){
    	$orderInfo = $param["orderInfo"];
    	$orderItemInfo = $param["orderItemInfo"];
    	$userName = $param["username"];
    	$email = $param["email"];
    	$orderNumber = $orderInfo[0]["order_num"];
    	$orderTotal = $orderInfo[0]["total"];
        $orderHtml =
<<<str_result
<table style="font-family:'宋体'; font-size:12px; color:#666666;">
        <!-- header begin -->
    
        <tr>
            <td background="http://i.akimimi.com/t/default_zh_cn/image/email/email_002.jpg" style="width:650px;height:95px;" colspan="2">
                <br/><br/><br/><br/><br/>
                    <span>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    </span>
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com">首页</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/mobile_and_accessories">手机</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/dc_and_accessories">数码相机</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/women_costume">时尚女装</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/makeup">化妆品</a></span>
            </td>       
        </tr>
        <!-- header end -->
        
        <!-- center end -->
        <tr>
            <td>
                <table>
                    <tr style="color:#000000">
                        <td>
                            <span style="font-weight:bold;">亲爱的：{$userName}</span><br/><br/>
                                                                            您的订单{$orderNumber}已经抵达您所在的高校。<br/><br/>
                                                                            订单信息<br/><br/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <table  width="440" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#F7FFF4">
                                <tr>
                                    <td width="250" height="25" align="center">商品名称</td>
                                    <td width="89" align="center">数量</td>
                                    <td width="73" align="center">单价</td>
                                </tr>
str_result;
        //显示订单详情
        $unit = UNIT; 
        foreach ($orderItemInfo as $item) {
        	$orderHtml .="
                                <tr>
                                    <td height='25' align='center'><a href='http://www.akimimi.com/p/{$item["url_title"]}'>{$item["title"]}</a></td>
                                    <td align='center'>{$item["quantity"]}</td>
                                    <td align='center'>{$unit}{$item["deal_price"]}</td>
                                </tr>
                          ";
        }
        
        $orderHtml .="                                
                                <tr>
                                    <td height='25' align='center'>&nbsp;</td>
                                    <td colspan='2' align='center'><h3 style='color:#47A618'>合计：{$unit}{$orderTotal}</h3></td>
                                </tr>
                                ";
        
         $orderHtml .=
<<<str_result
                            </table>
                        </td>
                    </tr>
                    <tr style="color:#000000;line-height:22px;">
                        <td>
                            <span style="font-weight:bold; color:#FF0000;">温馨提示：</span>
                            您所订购的商品已经抵达您所在高校。校园代理将为您送货上门。请耐心<br/>
                            等待，并保持联络畅通。马上您就可以收到心爱的商品了！如果在验货时发现商品存<br/>
                            在质量问题，您可以当场拒收，交由校园代理为您处理。同时，我们希望您可以现场<br/>
                            致电400-66-19686，米米客服会给予您最及时的处理！<br/>
                            欢迎您再次到阿基米米购物，祝您购物愉快！
                            <br/>
                        </td>
                    </tr>
                </table>
            </td>
            <td style="width:175px;" valign="top">
                <img src="http://i.akimimi.com/t/default_zh_cn/image/email/email_004.jpg"  alt=""/>
            </td>
        </tr>
        <!-- center end -->
        
        <!-- center begin -->
        <tr>
            <td colspan="2" valign="top">
                <img src="http://i.akimimi.com/t/default_zh_cn/image/email/email_001.jpg" alt="" />
            </td>
        </tr>
        <!-- center end -->
    
</table>  
      
str_result;
        //保存email日志
        $email_type = 4;
        $send_to = "$userName<$email>";
        $send_cc = "";
        $description = "订单<{$orderNumber}>米米代理已收货通知邮件";
        $arr_param = array(
            'email_type' => $email_type,
            'send_to' => $send_to,
            'send_cc' => $send_cc,
            'description' => $description,
            'created' => date('Y-m-d H:i:s'),
            'modified' => date('Y-m-d H:i:s')
        );
        self::saveLogs($arr_param);
        
        return $orderHtml;
    }
    
    //在线订单发邮件
    /**
     * 订单交易成功通知邮件
     */
    public function orderSuccessEmailToUser($orderId){
    	$config = $GLOBALS["config"];
        require_once "../". $GLOBALS["local"] ."/"."utility.php";
        //邮件title
        $successEmailTitle = DEALSUCCESS;
        //得到order信息
        $orderInfo = $this->orderItemDao->getItemInfoByOrderId($orderId);
        //订单的item信息
        $orderItemInfo = $this->orderItemDao->getItemInfoByOrderId($orderId);
        $orderNumber = $orderInfo["order_num"];
        $orderTotal = $orderInfo["total"];
        //得到用户信息
        $userId = $orderInfo["user_id"];
        $userInfo = $this->userDao->getUserById($userId);
        $userName = $userInfo[0]["name"];
        $email = $userInfo[0]["email"];
        $status = $userInfo[0]["status"];//未激活不发信
        
        $orderHtml =
<<<str_result
<table style="font-family:'宋体'; font-size:12px; color:#666666;">
        <!-- header begin -->
    
        <tr>
            <td background="http://i.akimimi.com/t/default_zh_cn/image/email/email_002.jpg" style="width:650px;height:95px;" colspan="2">
                <br/><br/><br/><br/><br/>
                    <span>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    </span>
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com">首页</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/mobile_and_accessories">手机</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/dc_and_accessories">数码相机</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/women_costume">时尚女装</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/makeup">化妆品</a></span>
            </td>       
        </tr>
        <!-- header end -->
        
        <!-- center end -->
        <tr>
            <td>
                <table>
                    <tr style="color:#000000">
                        <td>
                            <span style="font-weight:bold;">亲爱的：{$userName}</span><br/><br/>
                                                                            您的订单{$orderNumber}已交易成功。感谢您对阿基米米的支持，祝您购物愉快！<br/><br/>
                            <span style="color:#66B331;">您还可以对该订单的商品进行评价，并且可以获得10个积分。现在就去评价吧！</span><br/><br/>
str_result;
        
        foreach ($orderItemInfo as $item) {
            $orderHtml .= "<a target='_blank' href='http://www.akimimi.com/p/{$item[url_title]}'> http://www.akimimi.com/p/{$item[url_title]}</a><br/>";
        }
        
        $orderHtml .=
<<<str_result
                            <br/><span style="color:#a6a6a6;">如果您不能点击此链接，请将以上链接复制到浏览器地址栏中访问。</span>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <!--<table width="440" border="0" align="left" cellpadding="0" cellspacing="1" >
                                <tr>
                                    <td width="250" height="" align="center"></td>
                                    <td width="89" align="center"></td>
                                    <td width="73" align="center"></td>
                                </tr>-->
str_result;
        
         $orderHtml .=
<<<str_result
                            <!--</table>-->
                        </td>
                    </tr>
                    <tr style="color:#000000;line-height:22px;">
                        <td>
                            <span style="font-weight:bold; color:#FF0000;">温馨提示：</span>
                            对商品进行评论，可以获得积分（<a href="http://www.akimimi.com/u/help?type=mark">点击查看积分规则</a>）；<br/>
                            积分用途： a 可以兑换指定商品; <br/>
           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b 可提高用户等级。<br/>
                            如有任何疑问，欢迎致电：400-66-19686，或联系在线客服。<br/><br/>
                            欢迎您再次到阿基米米购物，祝您购物愉快！
                            <br/><br/>
                        </td>
                    </tr>
                </table>
            </td>
            <td style="width:175px;" valign="top">
                <img src="http://i.akimimi.com/t/default_zh_cn/image/email/email_006.jpg"  alt=""/>
            </td>
        </tr>
        <!-- center end -->
        
        <!-- center begin -->
        <tr>
            <td colspan="2" valign="top">
                <img src="http://i.akimimi.com/t/default_zh_cn/image/email/email_001.jpg" alt="" />
            </td>
        </tr>
        <!-- center end -->
    
</table>  
      
str_result;

         if(!empty($status)){
	         //发送email
	         MailUtil::sendMail($email, $successEmailTitle, $orderHtml);
	        //保存email日志
	        $email_type = 5;
	        $send_to = "$userName<$email>";
	        $send_cc = "";
	        $description = "订单<{$orderNumber}>交易成功通知邮件";
	        $arr_param = array(
	            'email_type' => $email_type,
	            'send_to' => $send_to,
	            'send_cc' => $send_cc,
	            'description' => $description            
	        );
	        self::saveLogs($arr_param);
         }
         
    }
    
    /*
     * 在线订单
     * 3.已发货通知邮件
     */
    public function sendedGoogsEmailToUser($orderId){
    	$config = $GLOBALS["config"];
        require_once "../". $GLOBALS["local"] ."/"."utility.php";
        //邮件title
        $alreadySendEmailTitle = ALREADYSENDGOODS;
        //得到order信息
        $orderInfo = $this->orderItemDao->getItemInfoByOrderId($orderId);
        //订单的item信息
        $orderItemInfo = $this->orderItemDao->getItemInfoByOrderId($orderId);
        $orderNumber = $orderInfo["order_num"];
        $orderTotal = $orderInfo["total"];
        //得到用户信息
        $userId = $orderInfo["user_id"];
        $userInfo = $this->userDao->getUserById($userId);
        $userName = $userInfo[0]["name"];
        $email = $userInfo[0]["email"];
        $status = $userInfo[0]["status"];//未激活不发信
    	
        //邮件主体
        $orderHtml1 =
<<<str_result
<table style="font-family:'宋体'; font-size:12px; color:#666666;">
        <!-- header begin -->
    
        <tr>
            <td background="http://i.akimimi.com/t/default_zh_cn/image/email/email_002.jpg" style="width:650px;height:95px;" colspan="2">
                <br/><br/><br/><br/><br/>
                    <span>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    </span>
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com">首页</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/mobile_and_accessories">手机</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/dc_and_accessories">数码相机</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/women_costume">时尚女装</a></span>&nbsp;&nbsp;&nbsp;
                    <span><a style="text-decoration:none;color:#F0FFEA;" href="http://www.akimimi.com/c/index/makeup">化妆品</a></span>
            </td>       
        </tr>
        <!-- header end -->
        
        <!-- center end -->
        <tr>
            <td>
                <table>
                    <tr style="color:#000000">
                        <td>
str_result;
        $orderHtmlAgent =
<<<str_result
                            <span style="font-weight:bold;">亲爱的：{$userName}</span><br/><br/>
                                                                            订单{$orderNumber}已发货，请您注意查收！<br/><br/>
str_result;
        $orderHtml4 =
<<<str_result
                                                                            订单信息<br/><br/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <table  width="440" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#F7FFF4">
                                <tr>
                                    <td width="250" height="25" align="center">商品名称</td>
                                    <td width="89" align="center">数量</td>
                                    <td width="73" align="center">单价</td>
                                </tr>
str_result;
        //显示订单详情
        $orderHtml5 = "";
        foreach ($orderItemInfo as $item) {
            $orderHtml5 .="
                                <tr>
                                    <td height='25' align='center'><a href='http://www.akimimi.com/p/{$item["url_title"]}'>{$item["title"]}</a></td>
                                    <td align='center'>{$item["quantity"]}</td>
                                    <td align='center'>￥{$item["deal_price"]}</td>
                                </tr>
                          ";
        }
        
        $orderHtml6 ="                                
                                <tr>
                                    <td height='25' align='center'>&nbsp;</td>
                                    <td colspan='2' align='center'><h3 style='color:#47A618'>合计：￥{$orderTotal}</h3></td>
                                </tr>
                                ";
        
         $orderHtml7 =
<<<str_result
                            </table>
                        </td>
                    </tr>
                    <tr style="color:#000000;line-height:22px;">
                        <td>
                            <span style="font-weight:bold; color:#FF0000;">温馨提示：</span>
                            您所订购的商品已经发货。阿基米米部分商品由北京库房直接发送，部<br/>
                            分商品由各地分仓发送。为了确保您订购的商品在运输途中不受损害，在发货前，每<br/>
                            一件商品都经过特殊的严密包装，并且托付中国最专业的快递公司负责全程配送。如<br/>
                            果您希望查询商品的运输情况。<br/>
                            可以在以下网站查询到您的物流信息：<br/>
                            顺丰快递：<a target="_blank" href="http://www.sf-express.com">http://www.sf-express.com</a><br/>
                    申通快递：<a target="_blank" href="http://www.sto.cn">http://www.sto.cn</a><br/>
                    中通快递：<a target="_blank" href="http://www.zto.cn">http://www.zto.cn</a><br/>
                    圆通快递：<a target="_blank" href="http://www.yto.ne.t.cn">http://www.yto.ne.t.cn</a><br/>
                    韵达快递：<a target="_blank" href="http://www.yundaex.com">http://www.yundaex.com</a><br/><br/>
                            欢迎您再次到阿基米米购物，祝您购物愉快！
                            <br/>
                        </td>
                    </tr>
                </table>
            </td>
            <td style="width:175px;" valign="top">
                <img src="http://i.akimimi.com/t/default_zh_cn/image/email/email_005.jpg"  alt=""/>
            </td>
        </tr>
        <!-- center end -->
        
        <!-- center begin -->
        <tr>
            <td colspan="2" valign="top">
                <img src="http://i.akimimi.com/t/default_zh_cn/image/email/email_001.jpg" alt="" />
            </td>
        </tr>
        <!-- center end -->
    
</table>  
      
str_result;
        
        if(!empty($status)){
	        $orderHtmlToUser = $orderHtml1.$orderHtmlAgent.$orderHtml4.$orderHtml5.$orderHtml6.$orderHtml7;
	        //发信
	        MailUtil::sendMail($email, $alreadySendEmailTitle, $orderHtmlToUser);
	        //保存email日志
	        $email_type = 3;
	        $send_to = "$userName<$email>";
	        $send_cc = "";
	        $description = "订单<{$orderNumber}>已发货通知邮件";
	        $arr_param = array(
	            'email_type' => $email_type,
	            'send_to' => $send_to,
	            'send_cc' => $send_cc,
	            'description' => $description,
	            'created' => date('Y-m-d H:i:s'),
	            'modified' => date('Y-m-d H:i:s')
	        );
	        self::saveLogs($arr_param);
        }
        
    }
    
    
    //保存发邮件日志记录
    public function saveLogs($arr_param){
        $this->emailLogDao->saveLogs($arr_param);
    }
	
}

